package com.xyzk.diagnose.activity.adapter;

import java.util.ArrayList;
import java.util.Map;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.TApplication;
import com.xyzk.diagnose.tools.Common;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DiagnoseAdapter extends BaseAdapter{
	private ArrayList<Map<String, String>> datas;
	
	public DiagnoseAdapter(ArrayList<Map<String, String>> datas) {
		this.datas = datas;
	}
	
	@Override
	public int getCount() {
		return datas == null ? 0: datas.size();
	}
	@Override
	public Object getItem(int position) {
		return datas == null ? null : datas.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	
	@Override
	public View getView(int position, View view, ViewGroup parent) {
		
		ViewHolder vh;
		if(view == null){
			view = View.inflate(TApplication.getContext(), R.layout.activity_diagnose_data_item,null);
			vh = new ViewHolder();
			vh.id = (TextView)view.findViewById(R.id.tv_diagnose_id);
			vh.name = (TextView)view.findViewById(R.id.tv_diagnose_testname);
			vh.content = (TextView)view.findViewById(R.id.tv_diagnose_content);
			vh.ctand = (TextView)view.findViewById(R.id.tv_diagnose_ctand);
			vh.result = (TextView)view.findViewById(R.id.tv_diagnose_result);
			view.setTag(vh);
		}else{
			vh = (ViewHolder) view.getTag();
		}
		Map<String, String> data = datas.get(position);
		if(Common.NG.equals(data.get(Common.RESULT))){
			view.setBackgroundColor(Color.RED);
		}else if(Common.NULL.equals(data.get(Common.RESULT))){
			view.setBackgroundColor(0xFF808080);
		}else{
			view.setBackgroundColor(Color.WHITE);
		}
		vh.id.setText(data.get(Common.ID));
		vh.name.setText(data.get(Common.TESTNAME));
		vh.content.setText(data.get(Common.CONTENT));
		vh.ctand.setText(data.get(Common.CTAND));
		vh.result.setText(data.get(Common.RESULT));
		return view;
	}
	
	class ViewHolder{
		TextView id;
		TextView name;
		TextView content;
		TextView ctand;
		TextView result;
	}
}
